﻿/*******************************************************************************
 * jQuery UI promptSpecial_City
 *
 * @author rowan
 ******************************************************************************/

/*  这里是定义模块的写法，
    custom/js/promptSpecial_City  模块的位置(必须是webviews下的)和模块名，所以该js 文件名必须为 promptSpecial_Car.js 
    ["base","waf","promptSpecial"]  为新定义的模块 所依赖的模块
    回调函数 function(base,waf,promptSpecial) 所传参数为模块名
    
    $.widget("ui.wafPromptSpecial_City", $.ui.wafPromptSpecial,{});
    意指 我此处定义的 ui.wafPromptSpecial_City 继承 $.ui.wafPromptSpecial,此句会把该模块注册到Jquery对象上
    
    其余格式固定
*/
mod.defineModule("extend/custom/ct/js/promptSpecial_ExpenseType_tree",["base","waf","promptSpecial"],function(base,waf,promptSpecial){
(function($, undefined) {
    $.widget("ui.wafpromptSpecial_ExpenseType_tree", $.ui.wafPromptSpecial,{
        options: {
            title: "预算项目",// 窗体标题
            rows: 10,//表格显示数据行数
            width: 500,
            height: 400,
			//filteritem: "longnumber = 'RCJF' or longnumber like 'RCJF!RCJF.01%' or longnumber like 'RCJF!RCJF.02%' or longnumber like 'RCJF!RCJF.03%' or longnumber like 'RCJF!RCJF.04%'",		//过滤预算的预算编码（树的节点也没显示）
            filteritem: "longnumber not like '2016!2016.SBGZYS%' and longnumber not like 'RCJF!RCJF.06%' "
						+ " and longnumber not like 'RCJF!RCJF.05%' and longnumber not like 'RCJF!RCJF.07%'"
						+ " and status != 2",		
			//defaultSearchItem:"name+number+defOrgUnit.name",
            //autoCompleteItem:"name+number+defOrgUnit.name",
            //showDisplayName:true,
            //treeDataUrl 由开发人员按需指定，返回数据有格式要求，我此处使用的eventBus实现的，定义了一个功能，名称是getTreeNodes,uipk为页面的uipk

            treeDataUrl : "/dynamicPage.do?method=doEvent&action=getChildNodes&uipk=" + waf.getUrlParams().uipk,
              
            //query 开发人员按需指定
            query : "com.kingdee.eas.basedata.assistant.app.F7CustomerProjectQuery",
            tableShrinkToFit : false,
            //将表格设置为不自动缩放，则按照colModel设置的宽度展示，长度超出则显示滚动条。
            //disdisplayColNames 可以规定要显示的字段，但其顺序是query中定义的顺序，该属性与colModel有一个就可以，若同时设置了这两个属性，colModel优先级更高。
            //displayColNames: ["number", "code","type","name", "description","level"],
            //colModel 可以指定表头的字段，宽度，显示属性，等等信息，表头字段顺序即为此处的顺序。
            colModel : [{"index":"id","name":"id","label":"ID","width":0,"hidden":true,"align":"left","filter":false,"formatter":null,"formatoptions":null,"dateType":"String","entityProName":"id"},
                {"index":"number","name":"number","label":"编码","width":100,"hidden":false,"align":"left","filter":true,"formatter":null,"formatoptions":null,"dateType":"String","entityProName":"longnumber"},
                {"index":"name","name":"name","label":"名称","width":150,"hidden":false,"align":"left","filter":true,"formatter":null,"formatoptions":null,"dateType":"String","entityProName":"name"},
                {"index":"type","name":"type","label":"类型","width":50,"hidden":false,"align":"left","filter":true,"formatter":null,"formatoptions":null,"dateType":"String","entityProName":"type"},
                {"index":"status","name":"status","label":"状态","width":50,"hidden":false,"align":"left","filter":true,"formatter":null,"formatoptions":null,"dateType":"String","entityProName":"status"},
                 {"index":"isLeaf","name":"isLeaf","label":"是否叶子节点","width":80,"hidden":false,"align":"left","filter":true,"formatter":null,"formatoptions":null,"dateType":"String","entityProName":"isLeaf"}
                ]
        },
        /*该函数用于当点击树的节点时，返回过滤条件，该方法由开发人员按自己需求进行覆盖
          注意：选中某个节点时，会把 treeNode.id 传到后台，后台可以在 request.getParameter("parentId") 取到，所以后台想办法取得request即可
          树 是异步加载的
        */
        _getTreeNodeFilter: function(){
            var selectedNodes = this.tree.wafTree('getSelectedNodes'),
                ret = "";
            	if(selectedNodes.length>0){
                var treeNode = selectedNodes[0];
                ret = "project.longnumber like  '" + treeNode.longnumber +  "%'";
            	}
            
            //刚刚弹出F7时，没有选中的节点，所以会返回过滤条件为空，因此数据会全部加载
            return ret;
        },
		treeHideNode: ['学科建设与人才培养', '课题类医院匹配经费', '课题类外来经费项目'],	//隐藏节点
        //该function 只在需要的时候才需要重写，如果不需要可以不重写
         _addTreeNodes: function(parentNode){
             var self = this;
             var treeUrl = waf.getContextPath() + this.options.treeDataUrl.replace("undefined", _self._uipk);
             var parentId = parentNode ? parentNode.id: "";
             var ajaxParam = {
                     url: treeUrl,
                     async: false,
                     showBlock: false,
                     data: {
                        //往后台传什么参数，可以在这里定义
                         "parentId":parentId,
						 "treeHideNode":self.treeHideNode.join(",")
                    },
                     success: function(data) {
                         if(!data || data.length<1){
                             return;
                         }
                         if(!parentNode){
                             self.clearOldTree();
                             var rootData = data[0];
                             var root = self.tree.wafTree("addNodes",null,
                                 { id:rootData.id, pId:'root', name:rootData.name,longnumber:rootData.longnumber, isParent:true,open:false},
                                 false)[0];
                             parentNode = root;
                             data.splice(0,1);
                             self.tree.wafTree("expandNode",parentNode,true,false,true,false);
                         }
                        
                         for(var i=0,l=data.length;i<l;i++){
                             var nodeData = data[i];
                             self.tree.wafTree("addNodes",parentNode,
                             { id:nodeData.id, pId:nodeData.pid, name:nodeData.name,longnumber:nodeData.longnumber, open:false,isParent:!nodeData.isLeaf},true);
                         }
                     },
                     error: function(data){
                         waf.msgBox.showError({summaryMsg:data});
						 $(".ui-promptSpecial-close").trigger("click");
						
                     },
                     fail: function(data){
                         waf.msgBox.showError({summaryMsg:data});
                     }
                 };
                 self.xhr = $.doPost(ajaxParam);
         }
    });
}(jQuery));
});